package com.smark.sbrabbitmqfanoutproducer.mq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.UUID;

/**
 * @author smark
 */
@Component
public class OrderService {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    //AmqpTemplate是一个接口，最终找到实现类也就是：RabbitTemplate
//    @Autowired
//    private AmqpTemplate template;

    //1、定义交换机
    @Value(value = "${mq.config.exchange}")
    private String exchangeName;


    public OrderService() {
    }

    /**
     * 模拟发送订单数据
     */
    public void sendMessages(int i){
        String orderId= UUID.randomUUID().toString();
        String message = i+" ===>你的订单信息是："+orderId+",日期是："+new Date();
        //发送消息
//        rabbitTemplate.convertAndSend(exchangeName,"email",message);
//        rabbitTemplate.convertAndSend(exchangeName,"log",message);
//        rabbitTemplate.convertAndSend(exchangeName,"weixin",message);
        rabbitTemplate.convertAndSend(exchangeName,"order",message);
    }


}
